package cn.itsnkkka.domain.enums;

import cn.itsnkkka.domain.dto.ARabbitMQObjectDTO;
import cn.itsnkkka.domain.dto.BRabbitMQObjectDTO;
import cn.itsnkkka.domain.dto.RabbitMQObjectDTO;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

/**
 * @author xuezipeng
 * @date 2023-04-23 12:24
 */
@Getter
public enum RabbitMQMessageTypeEnum {

    MESSAGE_TYPE_A(
            1, "A类型消息", ARabbitMQObjectDTO.class,
            "a_queue_exchange", "a_queue_routing_key", "a_queue"
    ),
    MESSAGE_TYPE_B(2, "B类型消息", BRabbitMQObjectDTO.class,
            "b_queue_exchange", "b_queue_routing_key", "b_queue"
    ),;

    @JsonValue
    private final Integer code;

    private final String desc;

    private final Class<? extends RabbitMQObjectDTO> messageTypeClazz;

    private final String exchangeName;

    private final String routingKeyName;

    private final String queueName;

    RabbitMQMessageTypeEnum(
            int code, String desc,Class<? extends RabbitMQObjectDTO> messageTypeClazz,
            String exchangeName, String routingKeyName, String queueName
    ) {
        this.code = code;
        this.desc = desc;
        this.messageTypeClazz = messageTypeClazz;
        this.exchangeName = exchangeName;
        this.routingKeyName = routingKeyName;
        this.queueName = queueName;
    }

    @Override
    public String toString() {
        return this.desc;
    }

    @JsonCreator
    public static RabbitMQMessageTypeEnum get(Integer code) {
        for (RabbitMQMessageTypeEnum item : RabbitMQMessageTypeEnum.values()) {
            if (code.equals(item.getCode())) {
                return item;
            }
        }
        return null;
    }
}
